package edu.westga.vocalengineer.audio.gui;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JPanel;

/**
 * EchoGuiTransform
 *  Implements an EchoTransform with an options panel.
 * @author mfarmer2
 */
public class EchoGuiTransform 
	extends edu.westga.vocalengineer.audio.transforms.EchoTransform 
	implements IGuiTransform {
	
	private JPanel optionsPanel;
	private JCheckBox echoEnabledCheck;
	private JTransformSliderPanel echoStrengthSlider;
	private JTransformSliderPanel echoDelaySlider;
	
	/**
	 * Sets up the EchoGuiTransform with some default values.
	 */
	public EchoGuiTransform() {
		super(8000,0.5f);
		optionsPanel = new JPanel();
		echoEnabledCheck = new JCheckBox("Enable Echo Transform");
		echoStrengthSlider = new JTransformSliderPanel("Strength (percent):", 5, 100, 50);
		echoDelaySlider = new JTransformSliderPanel("Delay (samples):", 1, 20000, 8000);
		JPanel tempPanel = new JPanel();
		tempPanel.setLayout(new BoxLayout(tempPanel, BoxLayout.PAGE_AXIS));
		tempPanel.add(echoDelaySlider);
		tempPanel.add(echoStrengthSlider);
		optionsPanel.add(echoEnabledCheck);
		optionsPanel.add(Box.createRigidArea(new Dimension(20,20)));
		optionsPanel.add(tempPanel);
		optionsPanel.setBorder(BorderFactory.createLineBorder(Color.black));
	}
	
	/**
	 * See AudioTransform.execute; applies a transform to samples
	 * by updating the state to reflect the sliders in the panel.
	 */
	@Override
	public short[] exectueWithGuiOptions(short[] samples) {
		if(!echoEnabledCheck.isSelected()) return samples;
		echoStrength = ((float)echoStrengthSlider.getValue() / 100.0f);
		echoDelay = echoDelaySlider.getValue();
		return execute(samples);
	}

	/**
	 * Returns the options JPanel.
	 */
	@Override
	public JPanel getOptionsPanel() {
		return optionsPanel;
	}

}
